package com.example.win.android_banduyujia.peopleactivity.activity.activity.openactivity.DataActivity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.example.win.android_banduyujia.R;
import com.example.win.android_banduyujia.lib.util.StrUtils;
import com.example.win.android_banduyujia.peopleactivity.ui.activity.BaseTitleBarActivity;

/**
 * Created by huchun on 2015/8/21.
 */
public class UpdateFirstActivity extends BaseTitleBarActivity {
    public static final String  USER_FIRST = "UpdateFirstActivity.USER_FIRST";

    private EditText  mEdtFirst;
    private ImageView mImageClose;
    private String    mNickFirst = " ";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_update_first);

        InitTitels();
       // InitDatas();
        InitViews();
    }

    private void InitTitels() {
        showLeftBackButton();
        setTitle(R.string.activity_layout_real_first_text);
        setRightTextViewListener(R.string.layout_data_save_button, mSaveTextListener);
    }

    private void InitDatas() {
        mNickFirst = getIntent().getStringExtra(USER_FIRST);
        mEdtFirst.setText(mNickFirst);
    }

    private void InitViews() {
        mEdtFirst = (EditText) findViewById(R.id.update_first_edit_text);
        mImageClose = (ImageView) findViewById(R.id.update_name_image_icon);
        mImageClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mEdtFirst.setText(" ");
            }
        });
        mEdtFirst.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) { }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) { }

            @Override
            public void afterTextChanged(Editable s) {
                mNickFirst = s.toString();
                if(StrUtils.isEmpty(mNickFirst)){
                    mImageClose.setVisibility(View.GONE);
                }else{
                    mImageClose.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    private View.OnClickListener  mSaveTextListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           if(StrUtils.isEmpty(mNickFirst)){
               showToast(R.string.personnal_info_activity_first_hint);
               return;
           }
            saveFirst();
        }
    };

    private void saveFirst() {

    }
}
